<template>
    <div>
        <div class="background-photo"></div>
        <div class="info container-lg">
            <div class="row">
                <div class="col-9">
                    <div class="info-top">
                        <div>
                            <nav style="--bs-breadcrumb-divider: '>>';" aria-label="breadcrumb">
                                <ol class="breadcrumb">
                                    <li class="breadcrumb-item">
                                        <router-link class="info-top-link" :to="{name: 'NewsInformation'}">首页</router-link>
                                    </li>
                                    <li class="breadcrumb-item" aria-current="page">
                                        <router-link class="info-top-link" :to="{name: 'NewsInformation'}">新闻资讯</router-link>
                                    </li>
                                    <li class="breadcrumb-item" aria-current="page">
                                        正文
                                    </li>
                                </ol>
                            </nav>
                        </div>
                        <div class="info-top-title">{{ current_record.title }}</div>
                        <div class="info-top-date">
                            <img src="@/assets/image/calendar.png" style="width: 20px; height: 20px; margin-right: 5px;">
                            <div>{{ current_record.createtime }}</div>
                            <div class="info-top-mark">作者：{{ current_record.author }}</div>
                            <div class="info-top-mark">出处：{{ current_record.source }}</div>
                        </div>
                    </div>
                    <div class="info-bottom" v-html="htmlContent"></div>
                </div>
                <div class="col-3">
                    <div class="sidebar">
                        <div class="sidebar-top">最新动态</div>
                        <div class="sidebar-bottom" v-for="n in [0, 1, 2, 4]" :key="n">
                            <div style="display: flex; align-items: center;">
                                <img src="@/assets/image/calendar.png" style="width: 20px; height: 20px; margin-right: 5px;">
                                <div>2024-11-28</div>
                            </div>
                            <div class="sidebar-bottom-text">【新华网】大学教授坚持写生22年，200余幅作品记录校园生活</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import { useRoute } from 'vue-router';
import { ref } from 'vue';
import { useStore } from 'vuex';

const store = useStore();
const route = useRoute();
const id = route.params.id;
const savedRecords = localStorage.getItem('records');
const records = savedRecords ? JSON.parse(savedRecords) : null; // 恢复为对象
const current_record = ref(null);
for (let record of records) {
    if (record.id == id) {
        current_record.value = record;
        break;
    }
}
store.commit("updateCurrentPage", localStorage.getItem('current_page'));
const htmlContent = current_record.value.htmlContent;

</script>

<style scoped>

.info {
    min-height: 600px;
    margin-bottom: 100px;
}

.background-photo {
    background-color: #92bad2;
    width: 100%;
    height: 400px;
}

.info-top {
    padding-top: 40px;
    padding-bottom: 20px;
    border-bottom: 1px solid #e5e5e5;
    color: #333333;
}
.info-top-link {
    text-decoration: none;
    color: inherit;
}
.info-top-title {
    text-align: center;
    font-size: 24px;
    padding: 10px 0;
}
.info-top-date {
    display: flex; 
    align-items: center;
    margin-top: 10px;
}
.info-top-mark {
    margin-left: 10px;
    font-size: 14px;
    color: #999999;
}
.info-bottom {
    padding-top: 20px;
    width: 100%;
}
.info-bottom img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain; /* 保证图片按比例缩放，且不超出容器 */
}

.sidebar {
    width: 100%;
    padding-top: 40px;
    padding-left: 20px;
}
.sidebar-top {
    width: 100%;
    height: 120px;
    background-color: #025394;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    color: white;
    font-weight: bold;
    user-select: none;
}
.sidebar-bottom {
    width: 100%;
    height: 130px;
    background-color: #f6f8fd;
    border-bottom: 1px dashed #91b7d7;
    padding: 0 15px;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    flex-direction: column;
}
.sidebar-bottom:last-child {
    border-bottom: none;
}
.sidebar-bottom-text {
    margin-top: 10px; 
    font-size: 14px;
    word-wrap: break-word;        /* 允许单词在需要时换行 */
    overflow: hidden;             /* 隐藏超出容器的部分 */
    text-overflow: ellipsis;      /* 超出部分显示省略号 */
    display: -webkit-box;         /* 使用 WebKit 布局来处理溢出 */
    -webkit-line-clamp: 2;        /* 限制文本行数为 3 行，超出部分显示省略号 */
    -webkit-box-orient: vertical; /* 垂直排列 */
    transition: color 0.3s ease;
    user-select: none;
}
.sidebar-bottom:hover {
    cursor: pointer;
}
.sidebar-bottom:hover .sidebar-bottom-text {
    color: #025394;
}

</style>